#!/bin/env python

import numpy as np

def f(x):
  tmp=np.zeros(n+1,"f8")
  for i in range(n):
    tmp += x[:,i]**2 
  return np.sin(tmp)

def resortxy(x,y):
  newy = np.sort(y)
  newx = x[np.argsort(y),:]
  return newx,newy

alpha = 1.0
beta = 2.0
h = 1.0
n = 2
x0 = np.random.random(size=n)
evector = np.identity(n)
xi = x0.reshape(1,-1) + h * evector
x = np.concatenate((x0.reshape(1,-1),xi),axis=0)

y = f(x)
x,y = resortxy(x,y)

xc = np.average(x[:-1,:],0)

xr = xc + alpha * (xc - x[-1,:])
yxr = f(xr.reshape(1,-1))